<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	
    public function index(){
    	if(IS_POST){
    		$user=M('admin');
    		$admin=I('admin');
    		$password=I('password');
    		$where['admin']=$admin;
    		$where['password']=$password;
    		$result=$user->where($where)->find();
    		
    		if($result){
    			session('admin',$where['admin']);
    		}else {
    			//不在技术管理员表中，查询是否为论坛管理员
			require './ucenter/config.inc.php';
			require './ucenter/uc_client/client.php';
			list($uid, $username, $password, $email) = uc_user_login($admin, $password);
			//if ($uid>0)echo "success";
			if($uid<0) $this->error("您还不是论坛会员");
			$ch = curl_init();
			curl_setopt($ch,CURLOPT_URL,"127.0.0.4/plugin.php?id=iltc_userinfoapi&action=user&key={$uid}");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			if(!$output = curl_exec($ch)){
				echo 'Curl error: ' . curl_error($ch);
			}
			$output =iconv("GBK", "UTF-8//ignore", $output );
			curl_close($ch);
			
			$output_array =json_decode($output,true);
			
			//print_r($output_array);
			if($output_array[data][groupid]==1)//echo "管理员";
			session('admin',$admin);
    		}
    	}
		$this->assign('title',"后台管理");
    	$this->display();
    }
    
    public function addMember(){
    	
    	if(IS_POST){
    		$user=M('userlist');
    		$user->create();
    		$user->add();
    		echo "添加成功";
    		echo "<a href='/hmtBook/index.php/home/list/index'>查看成员列表</a>";
    	}else {
    		$group=M('hmt_group');
    		$list=$group->where()->select();
    		$this->assign('list',$list);
    		$this->assign('title',$title);
    		$this->display();
    		 
    	}
    }
    public function editMember(){
    	
    }
    public function addGroup(){
    	//添加分组（如版主、技术）
    	if (IS_POST){
    		$group=M('hmt_group');
    		$group->create();
    		$group->add();
    		echo "添加成功！";
    	}else{
    	$this->assign('title',"添加分组");
    	$this->display();
    	}
    }
    public function logout(){
    	session(null);
    	$this->success("退出成功，再见！");
    }
}